cssprovider: Export correct API
authorBenjamin Otte <otte@redhat.com>
Thu, 18 Apr 2019 00:05:58 +0000 (02:05 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 18 Apr 2019 00:26:04 +0000 (02:26 +0200)
gtk_css_provider_get_named() is the old GTK3 style API to load themes.

Instead, export the function we currently use,
gtk_css_provider_load_named().

As a side effect we allow people to load a theme as often as they want
without conflicting with GTK's theme.

docs/reference/gtk/gtk4-sections.txt
gtk/gtkcssprovider.c
gtk/gtkcssprovider.h
gtk/gtkcssproviderprivate.h
gtk/gtksettings.c

index 458085c57e64da336509a5c7ca0352d351be417f..96d08652ddd35b7736292eea83a43d12d8e3adcd 100644 (file)
@@ -5076,7 +5076,7 @@ gtk_border_get_type
 <FILE>gtkcssprovider</FILE>
 <TITLE>GtkCssProvider</TITLE>
 GtkCssProvider
-gtk_css_provider_get_named
+gtk_css_provider_load_named
 gtk_css_provider_load_from_data
 gtk_css_provider_load_from_file
 gtk_css_provider_load_from_path
index 1e841fb2f3662659ff07652406c487d0df48947f..50a7bf80a4d59e907268084f664f4b304e12a9a1 100644 (file)
@@ -1342,7 +1342,7 @@ _gtk_css_find_theme (const gchar *name,
 }
 
 /**
- * _gtk_css_provider_load_named:
+ * gtk_css_provider_load_named:
  * @provider: a #GtkCssProvider
  * @name: A theme name
  * @variant: (allow-none): variant to load, for example, "dark", or
@@ -1351,12 +1351,12 @@ _gtk_css_find_theme (const gchar *name,
  * Loads a theme from the usual theme paths. The actual process of
  * finding the theme might change between releases, but it is
  * guaranteed that this function uses the same mechanism to load the
- * theme than GTK uses for loading its own theme.
+ * theme that GTK uses for loading its own theme.
  **/
 void
-_gtk_css_provider_load_named (GtkCssProvider *provider,
-                              const gchar    *name,
-                              const gchar    *variant)
+gtk_css_provider_load_named (GtkCssProvider *provider,
+                             const gchar    *name,
+                             const gchar    *variant)
 {
   gchar *path;
   gchar *resource_path;
@@ -1413,57 +1413,17 @@ _gtk_css_provider_load_named (GtkCssProvider *provider,
       if (variant)
         {
           /* If there was a variant, try without */
-          _gtk_css_provider_load_named (provider, name, NULL);
+          gtk_css_provider_load_named (provider, name, NULL);
         }
       else
         {
           /* Worst case, fall back to the default */
           g_return_if_fail (!g_str_equal (name, DEFAULT_THEME_NAME)); /* infloop protection */
-          _gtk_css_provider_load_named (provider, DEFAULT_THEME_NAME, NULL);
+          gtk_css_provider_load_named (provider, DEFAULT_THEME_NAME, NULL);
         }
     }
 }
 
-/**
- * gtk_css_provider_get_named:
- * @name: A theme name
- * @variant: (allow-none): variant to load, for example, "dark", or
- *     %NULL for the default
- *
- * Loads a theme from the usual theme paths
- *
- * Returns: (transfer none): a #GtkCssProvider with the theme loaded.
- *     This memory is owned by GTK+, and you must not free it.
- */
-GtkCssProvider *
-gtk_css_provider_get_named (const gchar *name,
-                            const gchar *variant)
-{
-  static GHashTable *themes = NULL;
-  GtkCssProvider *provider;
-  gchar *key;
-
-  if (variant == NULL)
-    key = g_strdup (name);
-  else
-    key = g_strconcat (name, "-", variant, NULL);
-  if (G_UNLIKELY (!themes))
-    themes = g_hash_table_new (g_str_hash, g_str_equal);
-
-  provider = g_hash_table_lookup (themes, key);
-  
-  if (!provider)
-    {
-      provider = gtk_css_provider_new ();
-      _gtk_css_provider_load_named (provider, name, variant);
-      g_hash_table_insert (themes, g_strdup (key), provider);
-    }
-  
-  g_free (key);
-
-  return provider;
-}
-
 static int
 compare_properties (gconstpointer a, gconstpointer b, gpointer style)
 {
index 9f05714173cec81c5eef6f8700b89b0a37c51ede..051305e573dc79d2abe359177d6391452345caec 100644 (file)
@@ -78,8 +78,9 @@ void             gtk_css_provider_load_from_resource (GtkCssProvider *css_provid
                                                       const gchar    *resource_path);
 
 GDK_AVAILABLE_IN_ALL
-GtkCssProvider * gtk_css_provider_get_named (const gchar *name,
-                                             const gchar *variant);
+void             gtk_css_provider_load_named     (GtkCssProvider  *self,
+                                                  const char      *name,
+                                                  const char      *variant);
 
 G_END_DECLS
 
index bca8e79464a7a8a94b25830454398eea70460ce5..e345d00120d599413dd79f0a6e810b0e8d57ba31 100644 (file)
@@ -26,10 +26,6 @@ gchar *_gtk_get_theme_dir (void);
 
 const gchar *_gtk_css_provider_get_theme_dir (GtkCssProvider *provider);
 
-void   _gtk_css_provider_load_named    (GtkCssProvider *provider,
-                                        const gchar    *name,
-                                        const gchar    *variant);
-
 void   gtk_css_provider_set_keep_css_sections (void);
 
 G_END_DECLS
index 354e70a0831aaf7972af5f1fbf17825bf2669432..79282b1804e4476a04f54ede1aa082bd37c45ed5 100644 (file)
@@ -2215,8 +2215,9 @@ settings_update_theme (GtkSettings *settings)
 
   get_theme_name (settings, &theme_name, &theme_variant);
 
-  _gtk_css_provider_load_named (priv->theme_provider,
-                                theme_name, theme_variant);
+  gtk_css_provider_load_named (priv->theme_provider,
+                               theme_name,
+                               theme_variant);
 
   /* reload per-theme settings */
   theme_dir = _gtk_css_provider_get_theme_dir (priv->theme_provider);